package com.jcl.recruit.apply.mapper;

import com.jcl.recruit.apply.model.InterviewSkd;
import org.apache.ibatis.annotations.*;

import java.util.Date;
import java.util.List;
import java.util.Map;

/**
 * @author 刘明新
 * @date 2018/8/6 下午3:05
 */
public interface InterviewSkdMapper {

    @InsertProvider(type=InterviewSkdSqlProvider.class, method="insertSelective")
    @Options(useGeneratedKeys=true,keyProperty="id")
    int insertSelective(InterviewSkd record);

    @UpdateProvider(type=InterviewSkdSqlProvider.class, method="updateByPrimaryKeySelective")
    int updateByPrimaryKeySelective(InterviewSkd record);

    @Select({
            "<script>",
            "select a.*,c.realname,c.work_last_position as position from interview_skd a left join interview b on a.interview_id = b.id left join resume c on b.resume_id = c.id",
            "<if test=\"token != null\">left join user d on a.hr_id = d.id</if>",
            "where",
            "<if test=\"scheduleStartDate != null\">a.schedule_date &gt;= #{scheduleStartDate} and</if>",
            "<if test=\"scheduleEndDate != null\">a.schedule_date &lt;= #{scheduleEndDate} and</if>",
            "<if test=\"token != null\">d.token = #{token} and</if>",
            "<if test=\"interviewId != null\">a.interview_id = #{interviewId} and</if>",
            "1=1",
            "order by a.id desc",
            "</script>"
    })
    List<Map<String,Object>> selectInterviewSkdsByDate(@Param("scheduleStartDate") Date scheduleStartDate, @Param("scheduleEndDate") Date scheduleEndDate,
                                                       @Param("token") String token, @Param("interviewId") Integer interviewId);

    @Select({
            "select * from interview_skd where id = #{id}"
    })
    Map<String,Object> selectPrimaryKeyById(@Param("id") Integer id);

    @Select({
        "select * from interview_skd where interview_id = #{interviewId}"
    })
    List<InterviewSkd> selectAllInterviewSkdsByInterviewId(@Param("interviewId") Integer interviewId);

    @Select({
            "select count(*) from interview_skd where schedule_date = #{date} and interview_id = #{interviewId} and hr_id = #{hrId}"
    })
    int selectCountByScheduleOptions(@Param("date") Date date, @Param("interviewId") Integer interviewId, @Param("hrId") Integer hrId);
}
